<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <img id="img" src="http://localhost:8080/undefined.png">
</body>
<script>
//监听图片加载失败,如果是失败给它一个默认图片
document.getElementById('img').onerror = function(){
    console.log('加载失败')
    // document.getElementById('img').src = 'https://img.yzcdn.cn/vant/cat.jpeg'//或者👇
    this.src = 'https://img.yzcdn.cn/vant/cat.jpeg'
}
</script>
</html>
